package com.easymin.daijia.server.demo;

import com.ybkj.daijia.server.utils.SslUtil;
import java.net.URL;
import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;
import lombok.SneakyThrows;
import org.junit.Test;
import org.springframework.http.ResponseEntity;
import org.springframework.web.client.RestTemplate;

/**
 * @author zhyu
 * @date 2020/1/7 14:53
 */
public class RestTemplateDemo {


    @SneakyThrows
    @Test
    public void testA(){
        String head = "https://wx.scezu.com/";
        String head2 = "https://wxtest.scezu.com/";
        String url = head + "api/shareCode/getWeixinShareQrCode?driverId={1}";
        URL urlPost = new URL(url);
        if("https".equalsIgnoreCase(urlPost.getProtocol())){//判定网址是否信任，不信任则调用忽略信任工具类SslUtil
            SslUtil.ignoreSsl();
        }
        RestTemplate restTemplate = new RestTemplate();
        String jsonStr = restTemplate.getForObject(url, String.class, 30 + "and" + "测试先生");
//        JSONObject re = JSONObject.parseObject(jsonStr);
        System.out.println(jsonStr);
    }
   @Test
   public void test(){
       Map<String, Object> map = new HashMap<>();
       map.put("minuteTime", 123);
       map.put("appKey", "sdf");
       map.put("passengerId", 123);
       String url = "http://192.168.110.204:7099/api/orders/v4up/getOverTimeOrder";
       StringBuilder sb = new StringBuilder(url);
       if (map.size() > 0) {
           sb.append("?");
           for (Entry<String, Object> entry : map.entrySet()) {
               if (sb.charAt(sb.length() - 1) == '?') {
                   sb.append(entry.getKey()).append("=").append(entry.getValue());
               } else {
                   sb.append("&").append(entry.getKey()).append("=").append(entry.getValue());
               }
           }
       }
       RestTemplate restTemplate = new RestTemplate();
       ResponseEntity<String> forEntity = restTemplate.getForEntity(sb.toString(), String.class, map);
       System.out.println(forEntity.getBody());
   }
}
